﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using LibraryO2S;

public partial class controls_admin_Needs : Pages_Base
{
    private DataTable objDT;
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
            base.loadCategories(ddlCategories, 2);
            loadNeeds();
        }
    }
    private void loadNeeds()
    {
        try
        {
            objDT = BO_Needs.SelectCategory(Convert.ToInt32(ddlCategories.SelectedValue), 1, int.MaxValue, 1);
            base.bindRepeater(rptNeeds, objDT, divMessage);
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi trong quá trình xử lý<br />" + ex.Message);
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx?module=needadd");
    }
    protected void rptNeeds_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            string commandName = e.CommandName;
            int need = Convert.ToInt32(e.CommandArgument);
            if (commandName.Equals("del"))
            {
                BO_Needs.Delete(need);
                divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Xóa thành công .");
            }
            loadNeeds();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi: <br />" + ex.Message);
        }
    }
    protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadNeeds();
    }
}
